import React from 'react';
import type { FormProps } from 'antd';
import { Button, Checkbox, Form, Input } from 'antd';
import http from '../../api/http'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next';


type FieldType = {
  account?: string;
  password?: string;
  remember?: string;
};



const Login: React.FC = () => {
  const navigate = useNavigate()
  const { t, i18n } = useTranslation();

  const onFinish: FormProps<FieldType>['onFinish'] = async (values) => {
    const res = await http.post('/login', values)
    console.log(res, '登录')
    if (res.data.token) {
      localStorage.setItem('token', res.data.token)
      navigate('/')
    }
  };

  return (
    <div className='
    w-full
    h-[1000px]
    bg-pink-200
    '>
      <Form
        name="basic"
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
        style={{ width: '600px', height: '600px', marginLeft: '20%' }}
        initialValues={{ remember: true }}
        onFinish={onFinish}
        autoComplete="off"
      >
        <h1 style={{marginLeft:'55%',fontWeight:'bold',fontSize:'40px'}}>{t('login')}</h1>
        <Form.Item<FieldType>
          label="用户名"
          name="account"
          rules={[{ required: true, message: '请输入用户名!' }]}
        >
          <Input />
        </Form.Item>

        <Form.Item<FieldType>
          label="密码"
          name="password"
          rules={[{ required: true, message: '请输入密码!' }]}
        >
          <Input.Password />
        </Form.Item>

        <Form.Item<FieldType> name="remember" valuePropName="checked" label={null}>
          <Checkbox>记住我</Checkbox>
          <span style={{ color: "blue", marginLeft: '60%' }}>忘记密码?</span>
        </Form.Item>

        <Form.Item label={null}>
          <Button style={{ width: '450px', marginLeft: '-50px' }} type="primary" htmlType="submit">
            登录
          </Button>
        </Form.Item>


        <Form.Item label={null}>
          <Button style={{ width: '120px' }}>手机登录</Button>
          <Button style={{ width: '120px' }}>二维码登录</Button>
          <Button style={{ width: '120px' }}>注册</Button>
        </Form.Item>

      </Form>
    </div>
  )
}

export default Login;